#define _CRT_SECURE_NO_WARNINGS 1
struct ListNode* getIntersectionNode(struct ListNode* headA, struct ListNode* headB) {
    struct ListNode* cur1, * cur2;
    cur1 = headA;
    cur2 = headB;
    int lenA = 0, lenB = 0;

    while (cur1->next)
    {
        cur1 = cur1->next;
        lenA++;
    }

    while (cur2->next)
    {
        cur2 = cur2->next;
        lenB++;
    }
    if (cur1 != cur2)
    {
        return NULL;
    }

    int gap = abs(lenA - lenB);
    struct ListNode* longer = headA;
    struct ListNode* shorter = headB;
    if (lenA < lenB)
    {
        longer = headB;
        shorter = headA;
    }

    while (gap--)
    {
        longer = longer->next;
    }

    while (longer != shorter)
    {
        longer = longer->next;
        shorter = shorter->next;
    }

    return longer;
}